package com.dongdong.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdong.domain.Result;
import com.dongdong.em.ResultEnum;
import com.dongdong.pojo.*;
import com.dongdong.service.TbGoodsDescService;
import com.dongdong.service.TbItemCatService;
import com.dongdong.service.TbSellerService;
import com.dongdong.service.TbTypeTemplateService;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("goods")
public class TbGoosDesc {
    @Reference
    private TbGoodsDescService tbGoodsDescService;
    @Reference
    private TbItemCatService tbItemCatService;
    @Reference
    private TbTypeTemplateService tbTypeTemplateService;
    @RequestMapping("getShow")
    public String getShow(){
        return "admin/goods_edit";
    }
    @RequestMapping("getInfo")
    @ResponseBody
    public Result getInfo(Long id){
     List<TbItemCat> list = tbItemCatService.getInfo(id);
        return Result.buildResult(ResultEnum.SUCCESS).setData(list);
    }
    @RequestMapping("getInfoId")
    @ResponseBody
    public Result getInfoId(Long id){
        TbItemCat tbItemCat =tbItemCatService.getInfoId(id);
         TbTypeTemplate tbTypeTemplate=  tbTypeTemplateService.getTypeId(tbItemCat.getTypeId());
        return Result.buildResult(ResultEnum.SUCCESS).setData(tbItemCat).setResults(tbTypeTemplate);
    }
    @RequestMapping("addInfo")
    @ResponseBody
    public Result addInfo(TbGoodsDesc tbGoodsDesc , TbGoods tbGoods){
        TbSeller tbSeller = (TbSeller) SecurityUtils.getSubject().getPrincipal();
        tbGoods.setSellerId(tbSeller.getSellerId());
        tbGoodsDescService.addInfo(tbGoodsDesc,tbGoods);
        return Result.buildResult(ResultEnum.SUCCESS);
    }
}
